package com.dingli.servlet.ajax;

import com.dingli.DAO.AdminDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "deleteUserServlet", value = "/deleteUser")
public class deleteUserServlet extends HttpServlet {
    private AdminDao adminDao = new AdminDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String userId = request.getParameter("userId");
        try {
            int flag = adminDao.deletePerson(userId);
            if(flag > 0){
//                response.sendRedirect("/views/adminManage.jsp");
                response.getWriter().write("true");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

